package com.ycsd.invest.order.business.eventplugin;

import cn.hutool.json.JSONArray;
import com.alibaba.dubbo.common.json.JSON;
import com.alibaba.dubbo.common.json.ParseException;
import kd.bos.bec.api.IEventServicePlugin;
import kd.bos.bec.model.EntityEvent;
import kd.bos.bec.model.JsonEvent;
import kd.bos.bec.model.KDBizEvent;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.workflow.engine.WfUtils;

public class OrderInfoEvent implements IEventServicePlugin {
    @Override
    public Object handleEvent(KDBizEvent evt) {
        if (evt instanceof EntityEvent) {//苍穹事件
            EntityEvent entityEvent = (EntityEvent) evt;//类型转换
            String businesskey = entityEvent.getBusinesskeys().get(0);
            String entityNumber = entityEvent.getEntityNumber();
            DynamicObject obj = BusinessDataServiceHelper.loadSingle(businesskey, entityNumber);
            Long evtID = evt.getEventId();
            String source = evt.getSource();//传递的事件参数
        } else {//自定义事件
            JsonEvent jsonEvent = (JsonEvent) evt;//类型转换
            String source = jsonEvent.getSource();//传递的事件参数
            if (WfUtils.isNotEmpty(source)) {
                try {
                    JSONArray arr = (JSONArray) JSON.parse(source);
                } catch (ParseException e) {
                    throw new RuntimeException(e);
                }
            }
        }
        return null;
    }
}
